/**
 * Created by Coing on 2017/2/26.
 */

import java.util.HashMap;
import java.util.Map;

/**
 * 数据在个数比较少的情况下，可以使用，在数据比较多，感觉map，会不会更好呢。。
 *
 */
public class Solution2 {
    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> map = new HashMap<>();
        for (char c : magazine.toCharArray()) {
            int count = map.containsKey(c) ? map.get(c) + 1 : 1;
            map.put(c, count);
        }
        for (char c : ransomNote.toCharArray()) {
            int newCount = map.containsKey(c) ? map.get(c) - 1 : -1;
            if (newCount == -1) return false;
            map.put(c, newCount);
        }
        return true;
    }

    public static void main(String[] args) {
            Solution2 solution = new Solution2();
            System.out.println(solution.canConstruct("a", "b"));
            System.out.println(solution.canConstruct("aa", "ab"));
            System.out.println(solution.canConstruct("aa", "aab"));

    }


}
